﻿using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Texfina.Core.Common;
using Texfina.Common.Mg;
using Texfina.Common.Rh;
using Texfina.Core.Web;
using Texfina.Core.Data;
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using Texfina.Entity.Sy;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;
using RHBOMnt = Texfina.BOMnt.Rh;
using SYBOQry = Texfina.BOQry.Sy;

namespace RH
{
   public partial class wfVarCalculoMnt : EditPage
   {

      private string IdEditor
      {
         get { return this.ViewState["_idEditor"].ToString(); }
         set { this.ViewState["_idEditor"] = value; }
      }

      private string NuSeccion
      {
         get { return this.ViewState["_nuSec"].ToString(); }
         set { this.ViewState["_nuSec"] = value; }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
         if (this.IsPostBack)
         {
            this.LoadInPostBack();
            return;
         }
         this.LoadData();
      }

      public override void LoadInPostBack()
      {
         this.RegisterGeneralScripts();
         this.LockControls();
      }

      public override void LoadInitialSettings()
      {
         this.FormEditAction = (FormEditAction)Enum.Parse(typeof(FormEditAction), Request.QueryString["formEA"]);

         hdnidTipo.Value = Request.QueryString["idTipo"].ToString();

         if (hdnidTipo.Value == ConstTipoVariable.VARIABLE)
         {
             Label lbl = (Label)this.Master.FindControl("lblTitle");
             lbl.Text = "Variable";
         }
         else
         {
             Label lbl = (Label)this.Master.FindControl("lblTitle");
             lbl.Text = "Acumulador";
         }
      }

      public override void LoadListControls()
      {

         ETablaVC objE = new ETablaVC();
         RHBOQry.ITablaVC objBO = WCFHelper.GetObject<RHBOQry.ITablaVC>(typeof(RHBOQry.TablaVC));

         objE.DsVisibleEn = hdnidTipo.Value;
         DataTable dt = objBO.GetListXVisibleEn(objE);

         WebHelper.LoadListControl(ddlidTabla, dt, "dsDescrip", "idTablaVC", true, true);

         this.ListarAcumuladores();
         this.ListarCamposXAcumulador();
      }

      public override void DataToControls()
      {
        
         EVarCalc objE = new EVarCalc();
         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.VarCalc));
         objE.IdVarCalc = Request.QueryString["IdVarCalc"];
         objE = (EVarCalc)objBO.GetByKey(objE);

         if (objE != null)
         {
            WebHelper.EntityToControl(objE, "IdVarCalc", txtidVarCalc);
            WebHelper.EntityToControl(objE, "DsVarCalc", txtdsValCalc);
            WebHelper.EntityToControl(objE, "DsCondicion", txtdsCondicion);

            if (objE.DsCondicion != "")
               chkstCondicion.Checked = true;

            WebHelper.EntityToControl(objE, "IdTabla", ddlidTabla);

            hdnstPerSubCond.Value = ConstFlagEstado.ACTIVADO;
            if (ddlidTabla.SelectedValue != "")
            {
               ETablaVC objETbl = new ETablaVC();
               objETbl.IdTablaVC = ddlidTabla.SelectedValue;
               IBOQuery objBOTbl = WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.TablaVC));

               objETbl = (ETablaVC)objBOTbl.GetByKey(objETbl);

               if (objETbl != null)
                  hdnstPerSubCond.Value = objETbl.StPerSubCond;
            }
            this.ListarAcumuladores();
            WebHelper.EntityToControl(objE, "IdAcumula", ddlidAcumula);
            this.ListarCamposXAcumulador();
            WebHelper.EntityToControl(objE, "IdColumn", ddlidColumn);

            if (objE.StCondic1 == ConstFlagEstado.ACTIVADO)
            {
               rbStCondic1.Checked = true;
               rbStValor1.Checked = false;
               WebHelper.EntityToControl(objE, "DsCondic1", txtdsCondic1);
            }
            else
            {
               rbStValor1.Checked = true;
               rbStCondic1.Checked = false;
               WebHelper.EntityToControl(objE, "NuValor1", txtnuValor1);
            }

            if (objE.StCondic2 == ConstFlagEstado.ACTIVADO)
            {
               rbStCondic2.Checked = true;
               rbStValor2.Checked = false;
               WebHelper.EntityToControl(objE, "DsCondic2", txtdsCondic2);
            }
            else
            {
               rbStValor2.Checked = true;
               rbStCondic2.Checked = false;
               WebHelper.EntityToControl(objE, "NuValor2", txtnuValor2);
            }

         }

         if (hdnidTipo.Value == ConstTipoVariable.VARIABLE)
            return;

         EConcepRemu objECon = new EConcepRemu();
         IBOQuery objBOCon = WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.ConcepRemu));

         objECon.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         DataTable dt = objBOCon.GetList(objECon);

         foreach (DataRow dr in dt.Rows)
         {
            TreeNode nod = new TreeNode(dr["dsConRemu"].ToString(), dr["idConRemu"].ToString());
            nod.NavigateUrl = "javascript:void(0)";
            tvwstFiltro1.Nodes.Add(nod);

            nod = new TreeNode(dr["dsConRemu"].ToString(), dr["idConRemu"].ToString());
            nod.NavigateUrl = "javascript:void(0)";
            tvwstFiltro2.Nodes.Add(nod);
         }

         EVarCalcDet objEDet = new EVarCalcDet();
         RHBOQry.IVarCalc objBODet = (RHBOQry.IVarCalc)WCFHelper.GetObject<RHBOQry.IVarCalc>(typeof(RHBOQry.VarCalc));
         objEDet.IdVarCalc = txtidVarCalc.Text;
         dt = objBODet.GetDetailByParentKey(objEDet);

         DataView dv = new DataView(dt);
         dv.RowFilter = "stFiltro=1";
         foreach (DataRowView drv in dv)
         {
            foreach (TreeNode nod in tvwstFiltro1.Nodes)
            {
               if (nod.Value == drv["nuValor"].ToString())
                  nod.Checked = true;
            }
         }

         dv = new DataView(dt);
         dv.RowFilter = "stFiltro=2";
         foreach (DataRowView drv in dv)
         {
            foreach (TreeNode nod in tvwstFiltro2.Nodes)
            {
               if (nod.Value == drv["nuValor"].ToString())
                  nod.Checked = true;
            }
         }

      }

      public override void LockControls()
      {

         if (this.FormEditAction == FormEditAction.Edit || this.FormEditAction == FormEditAction.Delete)
            this.txtidVarCalc.Attributes.Add("readonly", "true");

         txtdsCondicion.Attributes.Add("readonly", "true");
         txtdsCondic1.Attributes.Add("readonly", "true");
         txtdsCondic2.Attributes.Add("readonly", "true");

         if (!chkstCondicion.Checked)
            bttDsCondicion.Attributes.Add("disabled", "true");

      }

      public override void RegisterGeneralScripts()
      {

         StringBuilder sb = new StringBuilder();

         sb.AppendLine("function validateEditFormPopup(key){");
         sb.AppendLine("switch(key)");
         sb.AppendLine(" {");
         sb.AppendLine("case '" + ConstMenuToolbarValue.BUTTON_SAVE + "': ");
         sb.AppendLine("case '_BTTEVAL': ");
         sb.AppendLine("var varRpta = isEmptyControl('" + this.txtdsFormula.ClientID + "','La Fórmula no puede estar vacia');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("menu_doPostBack('" + mnuPopup.ClientID + "','" + mnuPopup.UniqueID + "',key);");
         sb.AppendLine("break;");
         sb.AppendLine("case '" + ConstMenuToolbarValue.BUTTON_EXIT + "': ");
         sb.AppendLine("$find('" + this.mdlPopup.ClientID + "').hide();");
         sb.AppendLine("return false;");
         sb.AppendLine("break;");
         sb.AppendLine("}");
         sb.AppendLine("return false;");
         sb.AppendLine("}");

         sb.AppendLine("function validateEditForm(key){");
         sb.AppendLine("var varRpta = isEmptyControl('" + this.txtidVarCalc.ClientID + "','Ingrese el Nombre de la Variable de Cálculo');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var varRpta = isEmptyControl('" + this.txtdsValCalc.ClientID + "','Ingrese la Descripción');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var chk = document.getElementById('" + chkstCondicion.ClientID + "');");
         sb.AppendLine("if(chk.checked==true){");
         sb.AppendLine("varRpta = isEmptyControl('" + this.txtdsCondicion.ClientID + "','Ingrese la Condición General');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;}");
         sb.AppendLine("var rb = document.getElementById('" + rbStCondic1.ClientID + "');");
         sb.AppendLine("if(!rb.disabled){");
         sb.AppendLine("if(rb.checked==true){");
         sb.AppendLine("varRpta = isEmptyControl('" + this.txtdsCondic1.ClientID + "','Ingrese la Condición para la Condición Verdadero');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;}}");
         sb.AppendLine("rb = document.getElementById('" + rbStCondic2.ClientID + "');");
         sb.AppendLine("if(!rb.disabled){");
         sb.AppendLine("if(rb.checked==true){");
         sb.AppendLine("varRpta = isEmptyControl('" + this.txtdsCondic2.ClientID + "','Ingrese la Condición para la Condición Falso');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;}}");
         sb.AppendLine("menu_doPostBack('" + mnuToolbar.ClientID + "','" + mnuToolbar.UniqueID + "',key);");
         sb.AppendLine("}");

         sb.AppendLine("function OnChange" + chkstCondicion.ID + "(){");
         sb.AppendLine("   if(document.getElementById('" + chkstCondicion.ClientID + "').checked){ ");
         sb.AppendLine("      document.getElementById('" + this.bttDsCondicion.ClientID + "').disabled = false;");
         sb.AppendLine("   } else {");
         sb.AppendLine("      document.getElementById('" + this.bttDsCondicion.ClientID + "').disabled = true;");
         sb.AppendLine("   } return false;");
         sb.AppendLine("}");

         sb.AppendLine("function OnChange" + this.rbStCondic1.ID + "(){");
         sb.AppendLine("   if(document.getElementById('" + rbStCondic1.ClientID + "').checked){ ");
         sb.AppendLine("      document.getElementById('" + this.btnDsCondic1.ClientID + "').disabled = false;");
         sb.AppendLine("      document.getElementById('" + this.txtnuValor1.ClientID + "').disabled = true;");
         sb.AppendLine("   } else {");
         sb.AppendLine("      document.getElementById('" + this.btnDsCondic1.ClientID + "').disabled = true;");
         sb.AppendLine("      document.getElementById('" + this.txtnuValor1.ClientID + "').disabled = false;");
         sb.AppendLine("   } return false;");
         sb.AppendLine("}");

         sb.AppendLine("function OnChange" + this.rbStCondic2.ID + "(){");
         sb.AppendLine("   if(document.getElementById('" + rbStCondic2.ClientID + "').checked){ ");
         sb.AppendLine("      document.getElementById('" + this.btnDsCondic2.ClientID + "').disabled = false;");
         sb.AppendLine("      document.getElementById('" + this.txtnuValor2.ClientID + "').disabled = true;");
         sb.AppendLine("   } else {");
         sb.AppendLine("      document.getElementById('" + this.btnDsCondic2.ClientID + "').disabled = true;");
         sb.AppendLine("      document.getElementById('" + this.txtnuValor2.ClientID + "').disabled = false;");
         sb.AppendLine("   } return false;");
         sb.AppendLine("}");

         ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptRegister", sb.ToString(), true);

         this.chkstCondicion.Attributes.Add("onClick", "OnChange" + chkstCondicion.ID + "();");
         this.rbStCondic1.Attributes.Add("onClick", "OnChange" + rbStCondic1.ID + "();");
         this.rbStValor1.Attributes.Add("onClick", "OnChange" + rbStCondic1.ID + "();");
         this.rbStCondic2.Attributes.Add("onClick", "OnChange" + rbStCondic2.ID + "();");
         this.rbStValor2.Attributes.Add("onClick", "OnChange" + rbStCondic2.ID + "();");

      }

      public void RegisterEditPopupScripts()
      {

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if (e.Item == null)
            return;

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_SAVE:
            case ConstMenuToolbarValue.BUTTON_SAVENEW:
               if (this.FormEditAction != FormEditAction.Delete)
                  this.SaveData(e.Item.Value);
               else
                  this.DeleteData();
               break;

            case ConstMenuToolbarValue.BUTTON_EXIT:
               this.Response.Redirect("wfVarCalculoBnd.aspx?Filter=1");
               break;
         }

      }

      public override bool ValidateData()
      {
         if (this.FormEditAction == FormEditAction.AddNew || this.FormEditAction == FormEditAction.Copy)
         {

            IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.VarCalc));
            EVarCalc objE = new EVarCalc();

            objE.IdVarCalc = txtidVarCalc.Text;
            objE = (EVarCalc)objBO.GetByKey(objE);

            if (objE != null)
            {
               string strMsg = "La Variable de Calculo : " + txtidVarCalc.Text + " ya esta registrada";
               this.hdnMsgOPB.Value = this.CreatePostbackMessage("ATENCIÖN", "No se encotraron Resultados", TypeMessageAlert.atention, false, "");
               return false;
            }
         }

         return true;
      }

      public override void SaveData(String key)
      {
         if (this.ValidateData() == false)
            return;

         IEntityBase objE = (IEntityBase)this.CreateEntitySet();

         IBOUpdate objPro = (IBOUpdate)WCFHelper.GetObject<IBOUpdate>(typeof(RHBOMnt.VarCalc));

         String[] strRet = objPro.UpdateData(objE);
         String strMsg = "";

         switch (this.FormEditAction)
         {

            case FormEditAction.AddNew:
            case FormEditAction.Copy:
               strMsg = "Se ha registrado la Variable de Calculo : " + strRet[0].ToString();
               break;
            default:
               strMsg = "Se ha modificado la Variable de Calculo: " + this.txtidVarCalc.Text;
               break;
         }
         this.hdnMsgOPB.Value = this.CreatePostbackMessage("CORRECTO", strMsg, TypeMessageAlert.correct, false, "wfVarCalculoBnd.aspx?Filter=1");

      }

      protected void mnuPopup_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if (e.Item == null)
            return;

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_SAVE:
               if (!this.FormulaEvalSec1())
               {
                  mdlPopup.Show();
                  return;
               }
               txtdsCondicion.Text = txtdsFormula.Text;
               this.ClearEditPopup();
               break;

            case "_BTTEVAL":
               if (!this.FormulaEvalSec1())
               {
                  mdlPopup.Show();
                  return;
               }
               mdlPopup.Show();
               hdnMsgOPB.Value = this.CreatePostbackMessage("CORRECTO", "La Formula es correcta", TypeMessageAlert.correct, false, "");
               ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "msgPB", "MessageOnPostback();", true);
               break;
            case ConstMenuToolbarValue.BUTTON_EXIT:
               break;
         }

      }

      protected void bttDsCondicion_Click(object sender, EventArgs e)
      {

         this.lblTitlePopup.Text = "Editor de Formulas";
         this.IdEditor = ConstFormularioEditor.FORM1;
         this.NuSeccion = ConstFormularioEditorSeccion.SEC1;
         this.mdlPopup.Show();
         LoadDataEditPopup(null,0);

      }

      public override void LoadDataEditPopup(GridView grid, int rowIndex)
      {

         this.ClearEditPopup();

         TreeNode nodP = new TreeNode("Campos");
         nodP.NavigateUrl="javascript:void(0)";

         ETablaCF objE = new ETablaCF();
         objE.IdEditor = this.IdEditor;
         objE.NuSeccion = this.NuSeccion;

         RHBOQry.ITablaCF objBO = WCFHelper.GetObject<RHBOQry.ITablaCF>(typeof(RHBOQry.TablaCF));

         DataTable dt = objBO.GetCamposXSeccion(objE);

         foreach (DataRow dr in dt.Rows)
         {
            TreeNode nod = new TreeNode(dr["dsField"].ToString());
            nod.NavigateUrl = "javascript:void(0);";
            nod.ToolTip = dr["dsToolTip"].ToString();
            nodP.ChildNodes.Add(nod);
         }
         tvwCampoFor.Nodes.Add(nodP);

         txtdsFormula.Text = txtdsCondicion.Text;
      }

      public override void ClearEditPopup()
      {

         tvwCampoFor.Nodes.Clear();
         txtdsFormula.Text = "";
      }

      public void LockControlsPopup()
      {

      }

      public override void DeleteData()
      {
         IEntityBase objE = (IEntityBase)this.CreateEntitySet();
         IBOUpdate objPro = (IBOUpdate)WCFHelper.GetObject<IBOUpdate>(typeof(RHBOMnt.VarCalc));
         objPro.DeleteData(objE);

         this.hdnMsgOPB.Value = this.CreatePostbackMessage("CORRECTO", "Los Datos se han anulado correctamente", TypeMessageAlert.correct, false, "wfVarCalculoBnd.aspx?Filter=1");
      }

      public override Object CreateEntitySet()
      {
         EVarCalc objE = new EVarCalc();

         if (this.FormEditAction == FormEditAction.AddNew || this.FormEditAction == FormEditAction.Copy)
            objE.EntityState = EntityState.Added;
         else
         {
            IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.VarCalc));
            objE.IdVarCalc = Request.QueryString["IdVarCalc"];
            objE = (EVarCalc)objBO.GetByKey(objE);

            if (this.FormEditAction == FormEditAction.Edit)
               objE.EntityState = EntityState.Modified;
            if (this.FormEditAction == FormEditAction.Delete)
               objE.EntityState = EntityState.Deleted;

         }
         txtidVarCalc.Text = txtidVarCalc.Text;
         WebHelper.ControlToEntity(txtidVarCalc, objE, "IdVarCalc");
         WebHelper.ControlToEntity(txtdsValCalc, objE, "DsVarCalc");
         WebHelper.ControlToEntity(hdnidTipo, objE, "IdTipo");
         WebHelper.ControlToEntity(txtdsCondicion, objE, "DsCondicion");

         WebHelper.ControlToEntity(ddlidTabla, objE, "IdTabla");

         if (ddlidAcumula.SelectedItem != null)
            WebHelper.ControlToEntity(ddlidAcumula, objE, "IdAcumula");
         else
            objE.IdAcumula = "";

         if (ddlidColumn.SelectedItem != null)
            WebHelper.ControlToEntity(ddlidColumn, objE, "IdColumn");
         else
            objE.IdColumn = "";

         if (rbStCondic1.Checked)
         {
            objE.StCondic1 = ConstFlagEstado.ACTIVADO;
            WebHelper.ControlToEntity(txtdsCondic1, objE, "DsCondic1");
            objE.NuValor1 = 0;
         }
         else
         {
            objE.StCondic1 = ConstFlagEstado.DESACTIVADO;
            objE.DsCondic1 = "";
            WebHelper.ControlToEntity(txtnuValor1, objE, "NuValor1");
         }

         if (rbStCondic2.Checked)
         {
            objE.StCondic1 = ConstFlagEstado.ACTIVADO;
            WebHelper.ControlToEntity(txtdsCondic2, objE, "DsCondic2");
            objE.NuValor2 = 0;
         }
         else
         {
            objE.StCondic1 = ConstFlagEstado.DESACTIVADO;
            objE.DsCondic2 = "";
            WebHelper.ControlToEntity(txtnuValor2, objE, "NuValor2");
         }

         objE.StRegSis = ConstFlagEstado.DESACTIVADO;

         if (this.FormEditAction == FormEditAction.Delete)
            objE.StAnulado = ConstFlagEstado.ACTIVADO;
         else
            objE.StAnulado = ConstFlagEstado.DESACTIVADO;


         IList<EVarCalcDet> colE = new List<EVarCalcDet>();

         foreach (TreeNode tn in this.tvwstFiltro1.Nodes)
         {
            if (tn.Checked)
            {
               EVarCalcDet objEDet = new EVarCalcDet();
               objEDet.EntityState = EntityState.Added;
               objEDet.IdVarCalc = txtidVarCalc.Text;
               objEDet.StFiltro = ConstVariableCalcFiltro.VALOR1;
               objEDet.NuValor = tn.Value;
               objEDet.EntityState = EntityState.Added;
               colE.Add(objEDet);
            }

         }

         foreach (TreeNode tn in this.tvwstFiltro2.Nodes)
         {
            if (tn.Checked)
            {
               EVarCalcDet objEDet = new EVarCalcDet();
               objEDet.EntityState = EntityState.Added;
               objEDet.IdVarCalc = txtidVarCalc.Text;
               objEDet.StFiltro = ConstVariableCalcFiltro.VALOR2;
               objEDet.NuValor = tn.Value;
               objEDet.EntityState = EntityState.Added;
               colE.Add(objEDet);
            }
         }

         EVarCalcSet objESet = new EVarCalcSet();
         objESet.VarCalc = objE;
         objESet.VarCalcDet = colE;

         return objESet;
      }

      protected void ddlidTabla_SelectedIndexChanged(object sender, EventArgs e)
      {

         hdnstPerSubCond.Value = ConstFlagEstado.ACTIVADO;
         if (ddlidTabla.SelectedValue != "")
         {
            ETablaVC objE = new ETablaVC();
            objE.IdTablaVC = ddlidTabla.SelectedValue;
            IBOQuery objBO = WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.TablaVC));

            objE = (ETablaVC)objBO.GetByKey(objE);

            if (objE != null)
               hdnstPerSubCond.Value = objE.StPerSubCond;
         }

         this.ListarAcumuladores();
      }

      protected void ddlidAcumula_SelectedIndexChanged(object sender, EventArgs e)
      {
         this.ListarCamposXAcumulador();
      }

      private void ListarAcumuladores()
      {

         ETablaVCAcum objE = new ETablaVCAcum();
         RHBOQry.ITablaVC objBO = WCFHelper.GetObject<RHBOQry.ITablaVC>(typeof(RHBOQry.TablaVC));

         objE.IdTablaVC = ddlidTabla.SelectedValue;
         DataTable dt = objBO.GetAcumuladores(objE);

         ddlidAcumula.Items.Clear();
         ddlidColumn.Items.Clear();
         WebHelper.LoadListControl(ddlidAcumula, dt, "dsDescrip", "idAcumula", true, true);

      }

      private void ListarCamposXAcumulador()
      {

         ETablaVCAcumDet objE = new ETablaVCAcumDet();
         RHBOQry.ITablaVC objBO = WCFHelper.GetObject<RHBOQry.ITablaVC>(typeof(RHBOQry.TablaVC));

         objE.IdTablaVC = ddlidTabla.SelectedValue;
         objE.IdAcumula = ddlidAcumula.SelectedValue;
         DataTable dt = objBO.GetAcumuladorColumnas(objE);

         ddlidColumn.Items.Clear();
         WebHelper.LoadListControl(ddlidColumn, dt, "dsDescrip", "idColumna");

      }

      protected void btnDsCondic1_Click(object sender, EventArgs e)
      {
         this.IdEditor = ConstFormularioEditor.FORM1;
         this.NuSeccion = ConstFormularioEditorSeccion.SEC2;

         this.mdlPopup.Show();
      }

      public bool FormulaEvalSec1()
      {

         FormulaParser objParser = new FormulaParser(this.Page);

         foreach (TreeNode nod in tvwCampoFor.Nodes[0].ChildNodes)
            objParser.Fields.Add(new FormulaField(nod.Text,nod.Parent.Value));

         try
         {
            
            objParser.ParseCondition(txtdsFormula.Text);
         }
         catch (Exception ex)
         {
            hdnMsgOPB.Value = this.CreatePostbackMessage("ERROR", ex.Message, TypeMessageAlert.error, false, "");
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "msgPB", "MessageOnPostback();", true);
            return false;
         }

         return true;
      }
   }
}